from django.db import models
from django.forms import ModelForm
from django import forms


class Usuario(models.Model):
    nome = models.CharField(max_length=32)
    login = models.CharField(max_length=32)
    senha = models.CharField(max_length=100)    
    email = models.EmailField(max_length=150)
    data = models.DateTimeField(auto_now=True)
    
    def __unicode__(self):
        return self.nome
    
class UsuarioForm(ModelForm):    
    class Meta:
        model = Usuario
        widgets = {
            'senha': forms.PasswordInput(),
        }

    
class Empresa(models.Model):
    
    nome = models.CharField(max_length=100)
    data = models.DateTimeField(auto_now_add=True)
    
    def __unicode__(self):
        return self.nome
    
class EmpresaForm(ModelForm):
    class Meta:
        model = Empresa
        

class Maquina(models.Model):
    
    SISTEMAS = (
        ('w', 'Windows'),
        ('l', 'Linux'),
        ('m', 'MacOS'),
    )
    
    MEDIDAS_MEMORIA = (
        ('mb', 'Mb'),
        ('gb', 'Gb'),
    )
    
    nome = models.CharField(max_length=50, default='')
    ip = models.IPAddressField(max_length=30, default='0.0.0.0')
    processador  = models.CharField(max_length=50, default='')
    memoria = models.IntegerField(max_length=10, default=0)
    sistema_operacional = models.CharField(max_length=20, choices=SISTEMAS, default='w')
    unidade_medida = models.CharField(max_length=2, choices=MEDIDAS_MEMORIA, default='mb')
    empresa = models.ForeignKey(Empresa, default=1)
    
    def __unicode__(self):
        return self.nome + ' - ' + str(self.ip)
    

class MaquinaForm(ModelForm):
    class Meta:
        model = Maquina
        
        

class Chamado(models.Model):
    
    codigo = models.IntegerField(max_length=15)
    titulo = models.CharField(max_length=100)
    problema = models.TextField(max_length=1000)
    solucao = models.TextField(max_length=5000)
    duracao = models.CharField(max_length=10)
    data = models.DateTimeField(auto_now_add=True)
    usuario = models.ForeignKey(Usuario)
    maquina = models.ForeignKey(Maquina)



class ChamadoForm(ModelForm):
    class Meta:
        model = Chamado